<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            /* CSS3 新增样式 */
            box-sizing: border-box;
        }
        
        a {
            color: #000000;
            text-decoration: none
        }
        
        .login-header {
            width: 200px;
            font-size: 20px;
            transform: translateX(-50%);
            margin-left: 50%;
        }
        
        .login {
            display: none;
            width: 512px;
            height: 280px;
            border: #ebebeb solid 1px;
            position: fixed;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
            background: #ffffff;
            box-shadow: 0px 0px 20px #ddd;
            z-index: 999;
        }
        
        .login-title {
            width: 100%;
            height: 40px;
            line-height: 40px;
            margin: 10px 0px 20px 0px;
            text-align: center;
            font-size: 18px;
            position: relative;
            /* 鼠标一进入登陆标题，变成移动形状 */
            cursor: move;
        }
        
        .login-title span {
            position: absolute;
            right: -20px;
            top: -30px;
            background: #ffffff;
            font-size: 12px;
            border: #ebebeb solid 1px;
            width: 40px;
            height: 40px;
            border-radius: 20px;
        }
        
        .login-input {
            overflow: hidden;
            margin: 0px 0px 20px 0px;
        }
        
        .login-input label {
            float: left;
            width: 90px;
            height: 35px;
            padding-right: 10px;
            text-align: right;
            line-height: 35px;
            font-size: 14px;
        }
        
        .login-input input {
            float: left;
            line-height: 35px;
            height: 35px;
            width: 350px;
            border: #ebebeb 1px solid;
            text-indent: 5px;
        }
        
        .loginbtn {
            width: 50%;
            margin: 40px auto 0px auto;
            line-height: 40px;
            font-size: 14px;
            border: #ebebeb 1px solid;
            text-align: center;
        }
        
        .bg {
            display: none;
            width: 100%;
            height: 100%;
            position: fixed;
            top: 0px;
            left: 0px;
            background: rgba(0, 0, 0, .3);
        }
    </style>
</head>

<body>
    <div class="login-header"><a id="link" href="javascript:;">点击，弹出登录框</a></div>
    <!-- 登录框 -->
    <div class="login">
        <div class="login-title">登陆会员
            <span><a id="closebtn" href="javascript:;">关闭</a></span>
        </div>
        <div class="login-input">
            <label>用户名:</label>
            <input type="text" placeholder="请输入用户名" name="info[username]" id="username">
        </div>
        <div class="login-input">
            <label>登录密码：</label>
            <input type="password" placeholder="请输入登录密码" name="info[password]" id="password">
        </div>
        <div class="loginbtn"><a href="javascript:;" id="login-button-submit">登陆会员</a></div>
    </div>
    <!-- 遮盖层 -->
    <div class="bg"></div>

    <script>
        var login = document.querySelector('.login');
        var mask = document.querySelector('.bg');

        var link = document.querySelector('#link');
        var closebtn = document.querySelector('#closebtn');

        link.addEventListener('click', function() {
            login.style.display = 'block';
            mask.style.display = 'block';
        });
        closebtn.addEventListener('click', function() {
            login.style.display = 'none';
            mask.style.display = 'none';
        });

        // 拖拽效果 事件源为login-title
        var title = document.querySelector('.login-title');
        title.addEventListener('mousedown', function(e) {
            var posx = e.pageX - login.offsetLeft;
            var posy = e.pageY - login.offsetTop;

            function move(e) {
                login.style.left = e.pageX - posx + 'px';
                login.style.top = e.pageY - posy + 'px';
            }

            document.addEventListener('mousemove', move);
            title.addEventListener('mouseup', function() {
                document.removeEventListener('mousemove', move);
            });
        });
    </script>
</body>

</html>